package com.xunk.equipment.service.acrel.constant;

import org.apache.commons.collections4.map.CaseInsensitiveMap;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @ProjectName: xunk
 * @Package: com.xunk.equipment.service.acrel.constant
 * @ClassName: FlowmeterUnit
 * @Author: dongxiaoxin
 * @Description: 用量请求单位（最近一天，最近一个月，最近一季，最近半年，最近一年）
 * @Date: 2021/3/29 15:27
 * @Version: 1.0
 */
public enum FlowmeterUnitEnum {

    /**
     * 最近一月
     */
    LAST_DAY("day", "24h"),
    /**
     * 最近一月
     */
    LAST_MONTH("month", "30d"),

    /**
     * 最近一几
     */
    LAST_SEASON("season", "13w"),

    /**
     * 最近半年
     */
    LAST_HALF_YEAR("halfYear", "26w"),

    /**
     * 最近一年
     */
    LAST_YEAR("year", "52w");

    /**
     * 设备名称
     */
    String unit;

    /**
     * 设备的type 代号(可以存数据库)
     */
    String time;

    FlowmeterUnitEnum(String unit, String time) {
        this.unit = unit;
        this.time = time;
    }

    private static final Map<String, FlowmeterUnitEnum> DEVICE_NAME_ENUM_MAP = Arrays.stream(FlowmeterUnitEnum.values()).collect(Collectors.toMap(FlowmeterUnitEnum::getUnit, Function.identity(), (a, b) -> a, CaseInsensitiveMap::new));

    public static FlowmeterUnitEnum parseDeviceEnum(String unit) {
        return DEVICE_NAME_ENUM_MAP.getOrDefault(unit, LAST_DAY);
    }

    public static String getDefault() {
        return LAST_DAY.getUnit();
    }

    public static String getMonthUnit(){return LAST_MONTH.getUnit();}

    public static String getSeasonUnit(){return LAST_SEASON.getUnit();}

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }
}
